@extends('manage._layout')
@section('page-title')
    {{$name}}-模块列表
@stop
@section('page-breadcrumbs')
    <li>
        <a href="{{route('menu_list')}}" title="">
            菜单管理
        </a>
    </li>
    <li class="current">
        <a href="javascript:;" title="">
            模块列表
        </a>
    </li>
@stop
@section('page-buttons')
    <li>
        <a href="javascript:;" data-toggle="modal" data-target="#myModal" title="">
            <i class="icon-plus-sign"></i>
            <span>添加模块</span>
        </a>
    </li>
    <li>
        <a href="{{route('menu_list')}}" title="">
            <i class="icon-reply"></i>
            <span>返回</span>
        </a>
    </li>
@stop
@section('page-content')

    <table class="table table-striped">
        <thead>
        <tr>
            <th>名称</th>
            <th>方法名</th>
            <th>权限值</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @if (!empty($data))
            @foreach($data as $key=>$val)
                <tr>
                    <td>{{$val->module_name}}</td>
                    <td>{{$val->action}}</td>
                    <td>{{$val->value}}</td>
                    <td><a href="{{URL::route('menu_module_edit',['id'=>$val->id])}}" class="btn btn-xs btn-info" role="button"><span class="icon-pencil" aria-hidden="true"></span>修改</a></td>
                </tr>
            @endforeach
        @else
            <tr>
                <td colspan="4">暂无数据</td>
            </tr>
        @endif
        </tbody>
    </table>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        添加模块
                    </h4>
                </div>
                <div class="modal-body">
                    名称 <input type="text" class="form-control" style="width:200px;" name="name" id="name" placeholder="名称"><span style="color: red">菜单的操作模块名称</span>
                    </br>
                    方法名 <input type="text" class="form-control" style="width:150px;" name="action" id="action" placeholder="方法名"><span style="color: red">对应控制器方法名</span>
                    </br>
                    权限值 <input type="text" class="form-control"  style="width:100px;" name="value" id="value" placeholder="权限值"><span style="color: red">请按2的次幂填写(如查看1，增加2，修改4，删除8等等,不要填写已存在的权限值)</span>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button"  id="sub" class="btn btn-primary">
                        提交更改
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>

    <input type="hidden" id="menu_id" value="{{$menu_id}}">

    <script>
        $(document).ready(function () {
            $("#sub").click(function () {
                var menu_id=$('#menu_id').val();
                var module_name=$('#name').val();
                var value=$('#value').val();
                var action=$('#action').val();
                if(module_name==''){
                    layer.alert('请填写模块名称');
                    return false;
                }

                if(value==''){
                    layer.alert('请填写权限值');
                    return false;
                }

                if(action==''){
                    layer.alert('请填写方法名');
                    return false;
                }


                var postdata = {
                    menuId: menu_id,
                    moduleName:module_name,
                    value:value,
                    action:action
                };
                $.ajax({
                    type: 'POST',
                    url: '{{URL::route('menu_module_add_post')}}',
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                    data: postdata,
                    success: function (res) {
                        if (res.error == 0) {
                            layer.alert(res.message);
                            window.location.reload();
                        } else {
                            layer.alert(res.message);

                        }
                    },
                    error: function(XMLHttpRequest) {
                        if(XMLHttpRequest.status==403){
                            layer.alert(noAccessMsg);
                        }else{
                            layer.alert(otherErrorMsg);
                        }
                    }
                });


            });



        });

    </script>
@stop